<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@  taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<%@ include file="common/head.jsp" %>

<body class="fix-header fix-sidebar">

<!-- Preloader - style you can find in spinners.css -->
<div class="preloader">
    <svg class="circular" viewBox="25 25 50 50">
        <circle class="path" cx="50" cy="50" r="20" fill="none"
                stroke-width="2" stroke-miterlimit="10"/>
    </svg>
</div>
<!-- Main wrapper  -->
<div id="main-wrapper">
    <!-- header header  -->
    <%@ include file="common/header.jsp" %>
    <!-- End header header -->
    <!-- Left Sidebar  -->
    <%@ include file="common/nav.jsp" %>
    <!-- End Left Sidebar  -->
    <!-- Page wrapper  -->
    <div class="page-wrapper">
        <!-- 锐高软件 -->
        <%@ include file="../common/ruigao.jsp" %>

        <!--
                    作者：offline
                    时间：2018-03-26
                    描述：部门查看信息
                -->
        <div class="container-fluid">
            <!-- Start Page Content -->
            <div class="row justify-content-center">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="card-content">
                                <!-- Left sidebar -->
                                <div class="inbox-leftbar">
                                    <a class="btn btn-danger btn-block waves-effect waves-light"
                                       href="${pageContext.request.contextPath}/dept_add.jsp"> <font
                                            style="vertical-align: inherit;"> <font
                                            style="vertical-align: inherit;">添加部门</font>
                                    </font>
                                    </a>

                                </div>

                            </div>
                            <!-- End Left sidebar -->

                            <div>

                                <div role="toolbar">
                                    <div class="btn-group">
                                        <button class="btn btn-light waves-effect" type="button">
                                            <i class="mdi mdi-archive font-18 vertical-middle"></i>
                                        </button>
                                        <button class="btn btn-light waves-effect" type="button">
                                            <i class="mdi mdi-alert-octagon font-18 vertical-middle"></i>
                                        </button>
                                        <button class="btn btn-light waves-effect" type="button">
                                            <i class="mdi mdi-delete-variant font-18 vertical-middle"></i>
                                        </button>
                                    </div>
                                    <div class="btn-group show">
                                        <button aria-expanded="false" data-toggle="dropdown"
                                                class="btn btn-light dropdown-toggle waves-effect"
                                                type="button">
                                            公司
                                        </button>
                                        <div class="dropdown-menu">

                                            <%@ include file="../listall/companyall.jsp" %>
                                            <c:forEach var="sels" items="${selectcompany}">
                                                <a href="departshowlist?companyid=${sels.companyId}"
                                                   class="dropdown-item"> ${sels.companyName}</a>
                                            </c:forEach>
                                        </div>
                                    </div>

                                </div>

                                <div class="mt-4">
                                    <br/>
                                    <table class="table">
                                        <thead>
                                        <tr>
                                            <th>部门名称</th>
                                            <th>部门负责人</th>
                                            <th>部门电话</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>


                                        <c:forEach var="sel" items="${pageInfolist.getPageList()}">
                                            <tr>
                                                <td name="name">${sel.deptName}</td>
                                                <td>
                                                    <c:forEach var="users" items="${userList}">

                                                        <c:choose>
                                                            <c:when test="${sel.deptPrincipal eq users.userId }">
                                                                <a>${users.userName}</a>
                                                            </c:when>

                                                        </c:choose>

                                                    </c:forEach>
                                                </td>
                                                <td name="Phone">${sel.deptPhone}</td>
                                                <input type="hidden" name="ts" value="${sel.companyId}" id="lo">
                                                <input type="hidden" name="tss" value="${sel.deptBlurb}" id="lps">
                                                <td>
                                                    <button type="button"
                                                            class="btn btn-success btn-sm btn-rounded m-b-2 m-l-5">
                                                        <a href="${pageContext.request.contextPath}/deptServlets?id=${sel.deptId}&companyid=${sel.companyId}&deptPrincipal=${sel.deptPrincipal}"
                                                           style="color: white;">编辑</a>

                                                    </button>
                                                    <button type="button"
                                                            class="btn btn-danger btn-sm btn-rounded m-b-2 m-l-5 "
                                                            name="dels">
                                                        <input type="hidden" name="del" value="${sel.deptId}"
                                                               id="delid">删除
                                                    </button>
                                                </td>
                                            </tr>
                                        </c:forEach>


                                    </table>
                                </div>


                                <div class="table-responsive m-t-40">
                                    <div id="example23_wrapper" class="dataTables_wrapper">
                                        <div class="dataTables_paginate paging_simple_numbers"
                                             id="example23_paginate">

                                            <a href="?pageNo=1" class="paginate_button previous disabled"
                                               aria-controls="example23" data-dt-idx="0" tabindex="0"
                                               id="example23_previous"><font
                                                    style="vertical-align: inherit;"><font
                                                    style="vertical-align: inherit;">首页</font></font></a>


                                            <c:if test="${pageInfolist.getHasPrevPage() }">
                                                <a href="?pageNo=${pageInfolist.getPrevPage() }"
                                                   class="paginate_button previous disabled"
                                                   aria-controls="example23" data-dt-idx="0" tabindex="0"
                                                   id="example23_previous"><font
                                                        style="vertical-align: inherit;"><font
                                                        style="vertical-align: inherit;">上一页</font></font></a>
                                            </c:if>
                                            <span>
														<c:forEach items="${pageInfolist.groupPage }" var="pageI">
																	<a href="?pageNo=${pageI }"
                                                                       class="paginate_button "
                                                                       aria-controls="example23"
                                                                       data-dt-idx="${pageI }" tabindex="0"><font
                                                                            style="vertical-align: inherit;"><font
                                                                            style="vertical-align: inherit;">${pageI }</font></font></a>

                                                        </c:forEach>
													</span>
                                            <c:if test="${pageInfolist.getHasNextPage()  }">
                                                <a href="?pageNo=${pageInfolist.getNextPage() }"
                                                   class="paginate_button next" aria-controls="example23"
                                                   data-dt-idx="7" tabindex="0" id="example23_next"><font
                                                        style="vertical-align: inherit;"><font
                                                        style="vertical-align: inherit;">下一页</font></font></a>
                                            </c:if>

                                            <a href="?pageNo=${pageInfolist.totalPage }"
                                               class="paginate_button previous disabled"
                                               aria-controls="example23" data-dt-idx="0" tabindex="0"
                                               id="example23_previous"><font
                                                    style="vertical-align: inherit;"><font
                                                    style="vertical-align: inherit;">末页</font></font></a>

                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Container fluid  -->
<!-- footer -->
<%@ include file="common/footer.jsp" %>
<!-- End footer -->
<!-- End Page wrapper  -->
<%@ include file="common/js.jsp" %>
<!--
        作者：offline
        时间：2018-04-09
        描述：点击删除按钮弹窗
    -->

<script type="text/javascript">
    //
    $(function () {

        //判断当前登录的员工的权限
        var competence = ${competence};
        if (competence != 3) {
            $(".show").html("");
        }

        //点击删除
        $("button[name='dels']").click(function () {
            var dels = $(this).find("#delid").val();
            swal({
                    title: "您确定要解散该部门吗？",
                    animation: "slide-from-top",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    cancelButtonText: "取消",
                    confirmButtonText: "确定"
                },
                function (inputValue) {
                    if (inputValue === false) return false;
                    $.ajax({
                        url: "deptdelServlet",
                        type: "GET",
                        data: {"del": dels},
                        datatype: "JSON",
                        success: function (data) {
                            if (data) {
                                swal({
                                    title: "操作成功,<span style='color:red'>已删除</span>该部门",
                                    html: true,
                                    type: "success",
                                    showCancelButton: false,
                                    showConfirmButton: true,
                                    confirmButtonText: "确定",
                                }, function () {
                                    location.reload();
                                });
                            }
                        }
                    });
                });
        });
    });

</script>

</body>

</html>